﻿using UnityEngine;

namespace JH
{
    /// <summary>
    ///  获取RectTransform的屏幕坐标
    /// </summary>
    public static class GetScreenPosition
    {
        /// <summary>
        ///  获取RectTransform的屏幕坐标
        /// </summary>
        public static Vector2 GetScreenPositionEm(this RectTransform rectTransform)
        {
            var canvas = rectTransform.GetComponentInParent<Canvas>();
            var camera = canvas.renderMode == RenderMode.ScreenSpaceOverlay ? null : canvas.worldCamera;
            var screenPosition = RectTransformUtility.WorldToScreenPoint(camera, rectTransform.position);
            return screenPosition;
        }
    }
}